package com.jvtd.eyl.ui.main.my;


import com.jvtd.eyl.base.BasePresenter;
import com.jvtd.eyl.bean.binding.BrowseBean;
import com.jvtd.eyl.data.DbManager;
import com.jvtd.eyl.rxjava.JvtdRxSchedulers;
import com.jvtd.rxjava.JvtdObserverSubscriber;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.disposables.CompositeDisposable;

/**
 * 我的
 *
 * 作者:chenlei
 * 时间:2018/11/12 3:17 PM
 */
public class MyPresenter<V extends MyMvpView> extends BasePresenter<V> implements MyMvpPresenter<V>
{
  @Inject
  public MyPresenter(DbManager dbManager, CompositeDisposable disposable)
  {
    super(dbManager, disposable);
  }

  @Override
  public void getMyBrowseList() {
    if (!isAttachView()) return;
    getCompositeDisposable().add(getDbManager().getMyBrowseList(getCurrentUser().getUserId())
    .compose(JvtdRxSchedulers.handleObservableResult())
    .subscribeWith(new JvtdObserverSubscriber<List<BrowseBean>>(getMvpView()){
      @Override
      public void onNext(List<BrowseBean> myBrowseBeans) {
        super.onNext(myBrowseBeans);
        if (isAttachView()) getMvpView().getMyBrowseListSuccess(myBrowseBeans);
      }

      @Override
      public void onError(Throwable e) {
        super.onError(e);
        if (isAttachView()) getMvpView().getMyBrowseListFailed();
      }
    }));
  }
}
